const jwt = require('koa-jwt')
const { secret } = require("../config")

const Router = require('koa-router')
const router = new Router({ prefix: '/accounts' })

const {
    checkAccountExist,
    find, findById,
    create, update,
    delete: del,
    findJson
} = require('../controllers/accounts')

// 认证，解析token，并且从token中获取用户信息
const auth = jwt({ secret })

router.get('/', find)
router.get('/json', findJson)
router.get('/:id', checkAccountExist, findById)
router.post('/', auth, create)
router.patch('/:id', auth, checkAccountExist, update)
router.delete('/', auth, checkAccountExist, del)
module.exports = router